package com.arqui.admmon_module.server.handlers;

//import java.util.Date;
//import java.util.List;
//import com.arqui.admmon_module.shared.HistoricLoadEntity;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.rpc.ServiceException;

import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.arqui.admmon_module.client.action.HistoricLoad;
import com.arqui.admmon_module.client.action.HistoricLoadResult;
import com.arqui.admmon_module.server.services.FileLoadService;
import com.arqui.admmon_module.server.webservices.eventsmonitor.NonexistentEntityException;
import com.arqui.admmon_module.server.webservices.eventsmonitor.UnknownHostException;
import com.arqui.admmon_module.shared.HistoricLoadEntity;
import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;

public class HistoricLoadActionHandler implements
		ActionHandler<HistoricLoad, HistoricLoadResult> {

	@Inject
	public HistoricLoadActionHandler() {
	}

	@Override
	public HistoricLoadResult execute(HistoricLoad action, ExecutionContext context) throws ActionException {
		FileLoadService service = new FileLoadService();
		List<HistoricLoadEntity> result= new ArrayList<HistoricLoadEntity>();
		try {
			result = service.historicLoadService(action.getStartDate(), action.getEndDate());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (NonexistentEntityException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new HistoricLoadResult(result);
	}

	@Override
	public void undo(HistoricLoad action, HistoricLoadResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<HistoricLoad> getActionType() {
		return HistoricLoad.class;
	}
}
